#include <stdio.h>
#include <stdlib.h>
#include "list.h"

void test_single_linked_list() {
    slink list = NULL;

    printf("Testing sll_insert_by_location:\n");
    sll_insert_by_location(&list, 1, 10);
    sll_insert_by_location(&list, 2, 20);
    sll_insert_by_location(&list, 1, 5);
    //5 10 20
    printf("Testing sll_length_of_list: %d\n", sll_length_of_list(&list));

    printf("Testing sll_find_node_by_location:\n");
    sllnode *node = sll_find_node_by_location(&list, 2);
    if (node != NULL) {
        printf("Node at location 2 has data: %d\n", node->data);
    }

    printf("Testing sll_find_node_by_data:\n");
    int location;
    node = sll_find_node_by_data(&list, 20, &location);
    if (node != NULL) {
        printf("Node with data 20 found at location: %d\n", location);
    }

    printf("Testing sll_delete_by_location:\n");
    sll_delete_by_location(&list, 2);
    printf("List length after deletion: %d\n", sll_length_of_list(&list));
}

void test_double_linked_list() {
    dlink list = NULL;

    printf("\nTesting dll_insert_by_location:\n");
    dll_insert_by_location(&list, 1, 10);
    dll_insert_by_location(&list, 2, 20);
    dll_insert_by_location(&list, 1, 5);
    // 5 10 20

    printf("Testing dll_length_of_list: %d\n", dll_length_of_list(&list));

    printf("Testing dll_find_node_by_location:\n");
    dllnode *node = dll_find_node_by_location(&list, 2);
    if (node != NULL) {
        printf("Node at location 2 has data: %d\n", node->data);
    }

    printf("Testing dll_find_node_by_data:\n");
    int loc;
    node = dll_find_node_by_data(&list, 20, &loc);
    if (node != NULL) {
        printf("Node with data 20 found at location: %d\n", loc);
    }

    printf("Testing dll_delete_by_location:\n");
    dll_delete_by_location(&list, 2);
    printf("List length after deletion: %d\n", dll_length_of_list(&list));
}

int main() {
    test_single_linked_list();
    test_double_linked_list();
    return 0;
}